package com.rzht.framework.ui.activity;

import android.widget.EditText;

import com.rzht.framework.R;
import com.rzht.framework.base.BaseActivity;
import com.rzht.framework.model.login.User;
import com.rzht.framework.presenter.LoginPresenter;
import com.rzht.framework.utils.StringUtils;
import com.rzht.framework.utils.UIUtils;
import com.rzht.framework.view.LoginView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by lk on 2017/7/26.
 */

public class LoginActivity extends BaseActivity<LoginPresenter> implements LoginView {

    @BindView(R.id.username_et)
    EditText usernameEt;
    @BindView(R.id.password_et)
    EditText passwordEt;

    @Override
    protected int getLayout() {
        return R.layout.activity_login;
    }
    @Override
    protected LoginPresenter createPresenter() {
        return new LoginPresenter(this);
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    public String getUserName() {
        return usernameEt.getText().toString().trim();
    }

    @Override
    public String getPassword() {
        return passwordEt.getText().toString().trim();
    }

    @Override
    public void loginSuccess(User user) {
        UIUtils.showToastShort("登录成功");
    }

    @Override
    public void loginFailed() {
        UIUtils.showToastShort("登录失败");
    }

    @OnClick(R.id.login_bt)
    public void onClick() {

        if (StringUtils.isEmpty(getUserName())) {
            UIUtils.showToastShort("请输入帐号");
            return;
        }

        if (StringUtils.isEmpty(getUserName())) {
            UIUtils.showToastShort("请输入密码");
            return;

        }

        mPresenter.login();
    }
}
